package com.wangxin.study8.day;

import java.time.LocalTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.time.temporal.ChronoUnit;
import java.util.Locale;

/**
 * @ClassName LocalTimeMain
 * @Description LocalTime 定义了一个没有时区信息的时间，
 * 例如 晚上10点或者 17:30:15。下面的例子使用前面代码创建的时区创建了两个本地时间。
 * 之后比较时间并以小时和分钟为单位计算两个时间的时间差
 * @Author jojo.wang
 * @Date 2019-04-25 16:47
 * @Version 1.0
 **/
public class LocalTimeMain {
    public static void main(String[] args) {
        ZoneId zone1 = ZoneId.of("Europe/Berlin");
        ZoneId zone2 = ZoneId.of("Brazil/East");

        LocalTime now1 = LocalTime.now(zone1);
        LocalTime now2 = LocalTime.now(zone2);
        System.out.println("now1="+now1+";;now2="+now2+";;"+now1.isBefore(now2));

        long hoursBetween = ChronoUnit.HOURS.between(now1, now2);
        long minutesBetween = ChronoUnit.MINUTES.between(now1, now2);
        System.out.println(hoursBetween);
        System.out.println(minutesBetween);

        LocalTime late = LocalTime.of(23, 59, 59);
        //23:59:59
        System.out.println(late);

        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT).withLocale(Locale.GERMAN);
        LocalTime localTime = LocalTime.parse("13:37",dateTimeFormatter);
        System.out.println(localTime);

    }
}
